package com.thinkgem.jeesite.modules.sys.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.thinkgem.jeesite.kpoint.core.base.KpointBaseEntity;
import lombok.Data;

import java.util.List;

/**
 * @Author:Kongxiangsheng
 * @DesCription:
 * @Date:Created in 14:01 2018/8/13
 * @Modified By:
 */
@Data
public class SysMenu extends KpointBaseEntity {
    public static final String COL_PARENT_ID = "`parent_id`";
    public static final String COL_PARENT_IDS = "`parent_ids`";
    public static final String COL_NAME = "`name`";
    public static final String COL_SORT = "`sort`";
    public static final String COL_HREF = "`href`";
    public static final String COL_TARGET = "`target`";
    public static final String COL_ICON = "`icon`";
    public static final String COL_IS_SHOW = "`is_show`";
    public static final String COL_PERMISSION = "`permission`";
    private static final long serialVersionUID = 1L;

    /**
     * 父级菜单
     */
    private String parentId;
    /**
     * 所有父级编号
     */
    private String parentIds;
    /**
     * 名称
     */
    private String name;
    /**
     * 链接
     */
    private String href;
    /**
     * 目标（ mainFrame、_blank、_self、_parent、_top）
     */
    private String target;
    /**
     * 图标
     */
    private String icon;
    /**
     * 排序
     */
    private Integer sort;
    /**
     * 是否在菜单中显示（1：显示；0：不显示）
     */
    private String isShow;
    /**
     * 权限标识
     */
    private String permission;

    @JsonIgnore
    public static void sortList(List<SysMenu> list, List<SysMenu> sourcelist, String parentId, boolean cascade) {
        for (int i = 0; i < sourcelist.size(); i++) {
            SysMenu e = sourcelist.get(i);
            if (e.getParentId().equals(parentId)) {
                list.add(e);
                if (cascade) {
                    // 判断是否还有子节点, 有则继续获取子节点
                    for (int j = 0; j < sourcelist.size(); j++) {
                        SysMenu child = sourcelist.get(j);
                        if (child.getParentId().equals(e.getId())) {
                            sortList(list, sourcelist, e.getId(), true);
                            break;
                        }
                    }
                }
            }
        }
    }
}
